function write_serial(str)
% write_serial  Write to port initialized by tcs2.init
%   write_serial(str)

global TCS2_SERIAL

if isempty(TCS2_SERIAL)
    error('Serial connection not initialized. Please run tcs2.init_serial first.')
end

if tcs2.verbose >= 2
    disp(['sending: "' str '"'])
end

pause = 0.0001; %in seconds
if ~strcmp(TCS2_SERIAL.Port,'DUMMY')
    for i = 1:length(str)
        tic
        fwrite(TCS2_SERIAL,str(i),'uchar');
        while toc < pause
        end
    end
end
